package com.tmanager.web.servlets;

import com.google.inject.Injector;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

/**
 * User: paul
 * Date: Oct 12, 2010
 * Time: 6:29:35 PM
 */
public class InjectedHttpServlet extends HttpServlet {

    private Injector injector;

    @Override
    public void init(ServletConfig config) throws ServletException {
        super.init(config);
        ServletContext context = config.getServletContext();
        injector = (Injector) context.getAttribute(Injector.class.getName());
        if (injector == null) {
            throw new ServletException("Guice Injector not found");
        }
        injector.injectMembers(this);
    }

    public Injector getInjector() {
        return injector;
    }
}
